home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / distutils / command / install_egg_info.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  4.3 KB  |  92 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. """distutils.command.install_egg_info
  5.  
  6. Implements the Distutils 'install_egg_info' command, for installing
  7. a package's PKG-INFO metadata."""
  8. from distutils.cmd import Command
  9. from distutils import log, dir_util
  10. import os
  11. import sys
  12. import re
  13.  
  14. class install_egg_info(Command):
  15.     '''Install an .egg-info file for the package'''
  16.     description = "Install package's PKG-INFO metadata as an .egg-info file"
  17.     user_options = [
  18.         ('install-dir=', 'd', 'directory to install to'),
  19.         ('install-layout', None, 'custom installation layout')]
  20.     
  21.     def initialize_options(self):
  22.         self.install_dir = None
  23.         self.install_layout = None
  24.         self.prefix_option = None
  25.  
  26.     
  27.     def finalize_options(self):
  28.         self.set_undefined_options('install_lib', ('install_dir', 'install_dir'))
  29.         self.set_undefined_options('install', ('install_layout', 'install_layout'))
  30.         self.set_undefined_options('install', ('prefix_option', 'prefix_option'))
  31.         if self.install_layout:
  32.             basename = '%s-%s.egg-info' % (to_filename(safe_name(self.distribution.get_name())), to_filename(safe_version(self.distribution.get_version())))
  33.             if self.install_layout.lower() not in ('deb',):
  34.                 raise DistutilsOptionError('unknown value for --install-layout')
  35.             self.install_layout.lower() not in ('deb',)
  36.         elif self.prefix_option or 'real_prefix' in sys.__dict__:
  37.             basename = '%s-%s-py%s.egg-info' % (to_filename(safe_name(self.distribution.get_name())), to_filename(safe_version(self.distribution.get_version())), sys.version[:3])
  38.         else:
  39.             basename = '%s-%s.egg-info' % (to_filename(safe_name(self.distribution.get_name())), to_filename(safe_version(self.distribution.get_version())))
  40.         self.target = os.path.join(self.install_dir, basename)
  41.         self.outputs = [
  42.             self.target]
  43.  
  44.     
  45.     def run(self):
  46.         target = self.target
  47.         if os.path.isdir(target) and not os.path.islink(target):
  48.             dir_util.remove_tree(target, dry_run = self.dry_run)
  49.         elif os.path.exists(target):
  50.             self.execute(os.unlink, (self.target,), 'Removing ' + target)
  51.         elif not os.path.isdir(self.install_dir):
  52.             self.execute(os.makedirs, (self.install_dir,), 'Creating ' + self.install_dir)
  53.         
  54.         log.info('Writing %s', target)
  55.         if not self.dry_run:
  56.             f = open(target, 'w')
  57.             self.distribution.metadata.write_pkg_file(f)
  58.             f.close()
  59.         
  60.  
  61.     
  62.     def get_outputs(self):
  63.         return self.outputs
  64.  
  65.  
  66.  
  67. def safe_name(name):
  68.     """Convert an arbitrary string to a standard distribution name
  69.  
  70.     Any runs of non-alphanumeric/. characters are replaced with a single '-'.
  71.     """
  72.     return re.sub('[^A-Za-z0-9.]+', '-', name)
  73.  
  74.  
  75. def safe_version(version):
  76.     '''Convert an arbitrary string to a standard version string
  77.  
  78.     Spaces become dots, and all other non-alphanumeric characters become
  79.     dashes, with runs of multiple dashes condensed to a single dash.
  80.     '''
  81.     version = version.replace(' ', '.')
  82.     return re.sub('[^A-Za-z0-9.]+', '-', version)
  83.  
  84.  
  85. def to_filename(name):
  86.     """Convert a project or version name to its filename-escaped form
  87.  
  88.     Any '-' characters are currently replaced with '_'.
  89.     """
  90.     return name.replace('-', '_')
  91.  
  92.